#!/bin/sh
export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"
export PATH="$PATH:/bin:/usr/sbin:/usr/bin:/app/bin" 
substrA="mmcblk0"
substrB="mmcblk0p"
mountbase_point="/dev/mmcblk0"
result_mount=255
##create dir
mounted=`mount | grep $1 | wc -l`
#echo "^^^^^^^^^^^^^^^^^$mounted" >>/tmp/hot.log
if [ $mounted -ge 1 ]; then
#	echo "++++++++++++++++++++++++++++++++++" >>/tmp/hot.log
	killall ntfs-3g
	MOUNTS=$(mount | grep $substrA | cut -d' ' -f3)
	echo $MOUNTS >>/tmp/hot.log
	umount $MOUNTS
	rm -rf $MOUNTS
else

	if [ ! -d /mnt/media ]; then
      mkdir -p /mnt/media
	fi
	for i in `ls /dev/`; 
	do  

		result=$(echo $i | grep "$substrB")
		if [[ "$result" != "" ]]
		then
			if [ ! -d /mnt/media/$i ]; then
				 mkdir -p /mnt/media/$i
			fi
		   mount /dev/$i /mnt/media/$i
		    if [[ $? != 0 ]]
	            then
                      	 /usr/bin/ntfs-3g /dev/$i /mnt/media/$i
                    fi
	
		   result_mount=$?
		   mkdir -p /mnt/media/$i/5M
	           mkdir -p /mnt/media/$i/100M
		   break;
		else
		   echo " $i xx $substrB  =>$result"
		fi
	done
	echo "#.........................=>$result_mount" >>/tmp/hot.log
	if [[ $result_mount != 0 ]]
	then
		if [ ! -d /mnt/media/mmcblk0 ]; then
				 mkdir -p /mnt/media/mmcblk0
		fi
		mount $mountbase_point /mnt/media/mmcblk0
		if [[ $? != 0 ]]
		then
		mkdir -p /mnt/media/mmcblk0
		/usr/bin/ntfs-3g /dev/mmcblk0 /mnt/media/mmcblk0
		fi
		mkdir -p /mnt/media/mmcblk0/5M
                mkdir -p /mnt/media/mmcblk0/100M
	fi
	echo $?
fi
